<?php
class Suffix{
	/**
	 * 匹配域名后缀
	 * return boolean
	 */
	function matchSuffix($val){
		$suf=array('com','org','asia','ac','ae','ai','an','aq','as','au','az','bb','bf','bh','biz','bn','by','br','bv','cc','cf','ch','ck','cm','cn','co','cu','cy','de','dj','dz','edu','eg','et','fj','fm','fr','ge','gg','gi','gm','gov','gq','gs','gu','hk','hm','hr','id','il','in','info','int','ir','it','jo','ke','kh','kr','kz','lc','lk','ls','lu','ly','mobi','mc','me','mil','mh','mm','mo','mq','ms','mu','mx','mz','name','net','nf','nl','np','nz','pa','ph','pk','pm','pr','pt','qa','ro','rw','sb','se','sh','sj','sm','so','su','sz','td','tel','tg','tj','tn','tv','tp','tt','tz','ua','uk','um','uy','ve','vg','vn','ws','yu','zm');
		foreach($suf as $k=>$v){
			if($v==$val)
				return true;
		}
		return false;
	}
	/**
	 * 获取顶级域名
	 * return String
	 */
	function getTLD($domain=''){
		$ns = explode('.', $domain);
		$nns='';
		for($i=1; $i<=count($ns); $i++){
			if($this->matchSuffix($ns[count($ns)-$i])){
				$nns = $ns[count($ns)-$i].'.'.$nns;
			}else{
				$nns = $ns[count($ns)-$i].'.'.$nns;
				break;
			}

		}
		$nns = substr($nns, 0, strlen($nns)-1);
		return $nns;
	}
}
?>
